home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- ;#include <stdlib.h>
- #include "video.h"
- #include <unistd.h>
- #include <gl/gl.h>
-
- #ifndef FALSE
- #define FALSE 0
- #endif
-
- #ifndef TRUE
- #define TRUE 1
- #endif
-
- #define USAGE \
- "Usage: %s [-g] [-p p] [-f f] [-a a] [ -t t] [-h] \n\
- \t-g\tdisplay graphics\n\
- \t-p p\tprint message if # frame diffs exceeds <p> \n\
- \t-f f\ttotal number of frames grabbed \n\
- \t-a a\taccuracy when computing frame diff \n\
- \t-t t\tdelay time in hundredths of a sec \n\
- \t-h\tthis message \n"
-
- int diffBuffer(char *buf1, char *buf2, int x, int y, int acc)
- {
- int i, out;
- out = 0;
- for(i=0; i<x*y; i++){
- if((abs((int)(buf1[1] - buf2[1])) > acc) ||
- (abs((int)(buf1[2] - buf2[2])) > acc) ||
- (abs((int)(buf1[3] - buf2[3])) > acc)) out++;
- buf1 += 4; buf2 += 4;
- }
- return out;
- }
-
- void main(int argc, char **argv)
- {
- //
- // security program:
- // -f number of frames to grab (default 10)
- // -t ticks to delay between grabs (default 100)
- // -a accuracy threshold for compare (default 30)
- // -p print criteria (default 2000)
- // -g run graphics (default no)
- // -h help
- //
- int accuracy = 30;
- int delay = 100;
- int time = 10;
- int criteria = 2000;
- int hasGrafix = FALSE;
- int i, c, width, height, diffs;
- char *newFrame, *oldFrame;
- char *frame1, *frame2, *frame3;
- VideoIn *videoIn;
-
- while ((c = getopt(argc, argv, "hgt:f:a:p:")) != EOF){
- switch (c){
- case 'a':
- accuracy = atoi(optarg);
- break;
- case 't':
- delay = atoi(optarg);
- break;
- case 'f':
- time = atoi(optarg);
- break;
- case 'p':
- criteria = atoi(optarg);
- break;
- case 'g':
- hasGrafix = TRUE;
- break;
- case 'h':
- printf(USAGE, argv[0]);
- exit(0);
- }
- }
- videoIn = new VideoIn(2);
- if(!videoIn->hasVideo()) {
- fprintf(stderr,"No video input\n");
- exit(1);
- }
- width = videoIn->getWidth();
- height = videoIn->getHeight();
- oldFrame = new char [width*height*4];
- newFrame = new char [width*height*4];
- frame1 = oldFrame; frame2 = newFrame;
- videoIn->getBuffer();
- videoIn->loadFrame(width,height,frame1);
- if(hasGrafix){
- foreground();
- noborder();
- prefsize(width,height);
- long win = winopen("test");
- RGBmode();
- gconfig();
- // pixmode(PM_TTOB,1);
- }
- for(i=0; i<time; i++){
- videoIn->loadFrame(width,height,frame2);
- if(hasGrafix) lrectwrite(0,0,width-1, height-1, (ulong *)frame2);
- diffs = diffBuffer(frame1,frame2,width, height,accuracy);
- printf("There are %d differences\n",diffs);
- if(diffs > criteria){
- printf("There is motion.\n");
- }
- frame3 = frame1; frame1 = frame2; frame2 = frame3;
- sginap(delay);
- }
- videoIn->freeBuffer();
- delete [] newFrame;
- delete [] oldFrame;
- }
-